// interface Named {
//     name: string;
// }

// class Person {
//     name: string;
// }

// let p: Named;
// // OK, because of structural typing
// p = new Person();


// TypeScript结构化类型系统的基本规则是，如果x要兼容y，那么y至少具有与x相同的属性
// interface Named {
//     name: string;
// }

// let x: Named;
// // y's inferred type is { name: string; location: string; }
// let y = { name: 'Alice', location: 'Seattle' };
// x = y;

// 比较两个函数
// let x = (a: number) => 0;
// let y = (b: number, s: string) => 0;

// y = x; // OK
// x = y; // Error

// 函数参数双向协变    报错 TOOD
// enum EventType { Mouse, Keyboard }

// interface Event { timestamp: number; }
// interface MouseEvent extends Event { x: number; y: number }
// interface KeyEvent extends Event { keyCode: number }

// function listenEvent(eventType: EventType, handler: (n: Event) => void) {
//     /* ... */
// }

// // Unsound, but useful and common
// listenEvent(EventType.Mouse, (e: MouseEvent) => console.log(e.x + ',' + e.y));

// // Undesirable alternatives in presence of soundness
// listenEvent(EventType.Mouse, (e: Event) => console.log((<MouseEvent>e).x + ',' + (<MouseEvent>e).y));
// listenEvent(EventType.Mouse, <(e: Event) => void>((e: MouseEvent) => console.log(e.x + ',' + e.y)));

// Still disallowed (clear error). Type safety enforced for wholly incompatible types
// listenEvent(EventType.Mouse, (e: number) => console.log(e));

// 类
// 类与对象字面量和接口差不多
// 比较两个类类型的对象时，只有实例的成员会被比较。 静态成员和构造函数不在比较的范围内
// class Animal {
//     feet: number;
//     constructor(name: string, numFeet: number) { }
// }

// class Size {
//     feet: number;
//     constructor(numFeet: number) { }
// }

// let a: Animal;
// let s: Size;

// a = s;  //OK
// s = a;  //OK

// 泛型
// 编译 TOOD 
// interface Empty<T> {
// }
// let x: Empty<number>;
// let y: Empty<string>;

// x = y;  // okay, y matches structure of x